package com.threez.stream.ibm.binder;

import com.threez.core.utils.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.binder.Binding;
import org.springframework.cloud.stream.binder.ConsumerProperties;
import org.springframework.cloud.stream.binder.ProducerProperties;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.messaging.MessageChannel;

import javax.jms.JMSException;

@Slf4j
public class JmsSingleBinderIbmMQ extends JmsBinderAbstract {


        private JmsTemplate jmsTemplate = SpringUtils.getBean("pointJmsTemplate");
//    @Resource(name = "pointJmsTemplate")
//    private JmsTemplate jmsTemplate;

    @Override
    public Binding<MessageChannel> bindConsumer(String name, String group, MessageChannel inboundBindTarget, ConsumerProperties consumerProperties) {
        listenerConsumer(jmsTemplate, inboundBindTarget, session -> {
            try {
                return session.createQueue(name);
            } catch (JMSException e) {
                log.error("监听IBM MQ点对点的消息Topic: {}信息异常", name);
                log.error("监听IBM MQ点对点的消息Topic信息异常", e);
            }
            return null;
        });
        return () -> {
        };
    }


    @Override
    public Binding<MessageChannel> bindProducer(String name, MessageChannel outboundBindTarget, ProducerProperties producerProperties) {
        sendProducer(jmsTemplate, name, outboundBindTarget);
        return () -> {

        };
    }
}
